<template>
    <div>
        <top-simple-search @searchFun="query">
            <el-input v-model="searchParams.alias" size="small" :style="{width: '200px',marginRight:'10px'}" placeholder="请输入拟稿人" clearable></el-input>
            <el-date-picker
                    v-model="selectDate"
                    type="daterange"
                    range-separator="至"
                    start-placeholder="开始日期"
                    size="small"
                    format="yyyy-MM-dd"
                    value-format="yyyy-MM-dd"
                    style="margin-right: 10px"
                    end-placeholder="结束日期">
            </el-date-picker>
            <dept-select-tree v-model="searchParams.dept_id" class="treeselect" size="small" placeholder="请选择拟稿人部门" dept-type="all"  style="width: 215px; margin-right: 10px"></dept-select-tree>

            <el-input placeholder="当前办理人" v-model="searchParams.participant" size="small" style="width: 200px; margin-right: 10px" clearable></el-input>
            <template>
                <el-form-item label="" prop="num">
                    〔
                    <el-input v-model="searchParams.year" placeholder="年" :style="{width: '80px'}"
                              class="fwh"></el-input>
                    〕
                    <el-input v-model="searchParams.num" placeholder="归档编号" :style="{width: '90px'}"
                              class="fwh" ></el-input>
                    <!--        <el-input v-model="formData.collect_txt" placeholder="请输入收文文号" clearable :style="{width: '100%'}" :disabled="disabled"></el-input>-->
                </el-form-item>
            </template>
            <el-select v-model="searchParams.act_state_id" placeholder="是否办结" clearable size="small" style=" margin-right: 10px">
                <el-option label="办结" :value="4"/>
                <el-option label="非办结" :value="1"/>
            </el-select>
            <primary-button handle="daochu" @click="toExport" plain slot="other-button">导出</primary-button>
        </top-simple-search>
        <simple-table api-url="officialDocument/schoolSignature" ref="myTable" v-on="$listeners" :params="{category:'all',...searchParams}">

            <el-table-column align="left" prop="title" label="标题" min-width="200">
                <template slot-scope="{row}">
                    <my-link @to="toView(row)">{{row.title}}</my-link>
                </template>
            </el-table-column>
            <el-table-column align="left" prop="num" label="归档编号" width="120">
                <template slot-scope="{row}">
                    <span v-if="row.num"> {{row.year}}{{row.num}}</span>
                </template>
            </el-table-column>
            <el-table-column align="left" prop="type_id" label="公文类型" :formatter="typeFormatter"  width="100">
            </el-table-column>
            <el-table-column align="left" prop="alias" label="拟稿人" width="100">
            </el-table-column>
            <el-table-column align="left" prop="phone" label="手机" width="120" v-if="type_id==3">
            </el-table-column>
            <el-table-column align="left" prop="dept_info.name" label="拟稿部门" min-width="180">
            </el-table-column>
            <el-table-column align="left" prop="participant" label="当前办理人" width="140">
                <template slot-scope="{row}">
                    <span v-if="row.participant">{{row.participant}}</span>
                    <span v-else-if="row.act_state_id==4">
                        已办结
                    </span>
                    <span v-else-if="row.act_state_id==5">
                        被关闭
                    </span>
                </template>
            </el-table-column>
            <el-table-column align="left" prop="gmt_created" label="提交时间" width="170">
            </el-table-column>
            <!--            <el-table-column align="left" prop="recorder.alias" label="前序办理人"/>-->
            <el-table-column align="left" fixed="right" label="操作" width="120">
                <template slot-scope="{row}">
                    <detail-button @click="toView(row)"></detail-button>
                    <my-button handle="upspd" @click="toUpdateSpd(row)">更新</my-button>
                    <delete-button  @click="toDelete(row.id)"></delete-button>

                </template>
            </el-table-column>
        </simple-table>
    </div>
</template>
<script>
    import MyLink from "../../../components/MyLink/index";
    import DeptSelectTree from "@/components/Common/DeptSelectTree";
    import schoolSignature from "@/api/officialDocument/schoolSignature/index";
    import MySwitch from "../../../components/Common/MySwitch";
    import { getToken } from "@/utils/auth"; // 获取登录用户信息
    import qs from "qs";
    import PrimaryButton from "../../../components/Buttons/PrimaryButton";
    export default {
        name: "ListTable",
        components: {PrimaryButton, MySwitch,  DeptSelectTree, MyLink},
        props: [],
        data() {
            return {
                visible: false,
                detailVisible:false,
                currRow:{},
                selectDate:[],
                searchParams:{alias:"",starttime:"",endtime:"",search_value:"",dept:undefined,type:undefined,participant:undefined,year:undefined,num:undefined,act_state_id:undefined},
                options:[{label:"学校收文",value:2},{label:"学校发文",value:3}],
                categoryList:[],
                loading:false,
                interveneVisible:false,
            }
        },
        created() {
            this.searchParams.type = this.type_id
        },
        computed: {
            type_id() {
                let path = this.$route.fullPath.split("/")
                let key = path[path.length - 1]
                return key == "allSchoolForeign" ? 2 : 3
            },
        },
        methods: {
            toExport(){
                window.open(
                    `${process.env.VUE_APP_BASE_API}/api/document/export/?${qs.stringify(this.searchParams)}&token=${getToken()}`
                );
            },
            toUpdateSpd(row){
                schoolSignature.getDocumentUpspd(row.id).then(res=>{
                    this.msgSuccess(res.msg)
                })
            },
            typeFormatter(row){
                if(row.type_id==1){
                    return "校内签呈"
                }else if(row.type_id==2){
                    return "学校收文"
                }else if(row.type_id==3){
                    return "学校发文"
                }else if(row.type_id==4){
                    return "部门发文"
                }else{
                    return ""
                }
            },
            toHandle(row){
                this.$emit("showDialog",row,"handle")
            },
            toView(row){
                this.$emit("showDialog",row,"view")
            },
            query(queryData) {
                this.searchParams.search_value = queryData
                if(this.selectDate){
                    this.searchParams.starttime = this.selectDate[0]
                    this.searchParams.endtime = this.selectDate[1]
                }else{
                    this.searchParams.starttime = ""
                    this.searchParams.endtime = ""
                }
                this.$refs["myTable"].searchList(this.searchParams);
            },
            getList(){
                this.$refs["myTable"].searchList(this.searchParams);
            },
            toDelete(id) {
                this.$confirm("删除该数据, 是否继续?", "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                }).then(() => {
                    schoolSignature.deleteDocument(id).then(res => {
                        this.query();
                        this.msgSuccess(res.msg);
                    });
                });
            },
        }
    }
</script>
<style lang="scss" scoped>
    .treeselect{
        display: inline-block;
        width: 200px;
        vertical-align: top;
    }
    ::v-deep .vue-treeselect__control{height:32px;}
    ::v-deep .vue-treeselect__placeholder, .vue-treeselect__single-value{
        line-height: 32px;
    }
</style>
